package com.example.footballsystem.controller;

import com.example.footballsystem.entity.*;
import com.example.footballsystem.service.TeamGameService;
import com.example.footballsystem.service.TeamPersonService;
import com.example.footballsystem.service.TeamService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/Team")
@CrossOrigin(origins = "*")
public class TeamController {
    @Autowired
    TeamService teamService;
    @Autowired
    TeamGameService teamGameService;
    @Autowired
    TeamPersonService teamPersonService;
    //获取所有球队
    @PostMapping("/getAllTeam")
    public ResponseEntity<List<Team>> getAllTeam(){
        return ResponseEntity.ok().body(teamService.getAllTeam());
    }
    //添加球队
    @PostMapping("/addTeam")
    public ResponseEntity<Boolean> addTeam(@RequestBody Team team){
        log.info(team.toString());
        return ResponseEntity.ok().body(teamService.addTeam(team));
    }
    //删除球队
    @PostMapping("/deleteTeam")
    public ResponseEntity<Boolean> deleteTeam(@RequestBody List<Team> teams){
        for (int i=0;i<teams.size();i++){
            teamService.deleteTeam(teams.get(i));
        }
        return ResponseEntity.ok().body(true);
    }

    //获取所有比赛
    @PostMapping("/getAllTeamGame")
    public ResponseEntity<List<TeamGame>> getAllTeamGame(){
        return ResponseEntity.ok().body(teamGameService.getAllTeamGame());
    }
    //获取所选队伍的比赛
    @PostMapping("/getTeamGameByTeamID")
    public ResponseEntity<List<TeamGame>> getTeamGameByTeamID(@RequestBody int teamID){
        return ResponseEntity.ok().body(teamGameService.getTeamGameByTeamID(teamID));
    }
    //添加比赛
    @PostMapping("/addTeamGame")
    public ResponseEntity<Boolean> addTeamGame(@RequestBody TeamGame teamGame){
        log.info(teamGame.toString());
        return ResponseEntity.ok().body(teamGameService.addTeamGame(teamGame));
    }
    //删除比赛
    @PostMapping("/deleteTeamGame")
    public ResponseEntity<Boolean> deleteTeamGame(@RequestBody List<TeamGame> teamGames){
        for (int i=0;i<teamGames.size();i++){
            teamGameService.deleteTeamGame(teamGames.get(i));
        }
        return ResponseEntity.ok().body(true);
    }

    //获取所有球员
    @PostMapping("/getAllTeamPerson")
    public ResponseEntity<List<TeamPerson>> getAllTeamPerson(){
        return ResponseEntity.ok().body(teamPersonService.getAllTeamPerson());
    }
    //获取所选队伍的球员
    @PostMapping("/getTeamPersonByTeamID")
    public ResponseEntity<List<TeamPerson>> getTeamPersonByTeamID(@RequestBody int teamID){
        return ResponseEntity.ok().body(teamPersonService.getTeamPersonByTeamID(teamID));
    }
    //添加球员
    @PostMapping("/addTeamPerson")
    public ResponseEntity<Boolean> addTeamPerson(@RequestBody TeamPerson teamPerson){
        return ResponseEntity.ok().body(teamPersonService.addTeamPerson(teamPerson));
    }
    //删除球员
    @PostMapping("/deleteTeamPerson")
    public ResponseEntity<Boolean> deleteTeamPerson(@RequestBody List<TeamPerson> teamPersons){
        for (int i=0;i<teamPersons.size();i++){
            teamPersonService.deleteTeamPerson(teamPersons.get(i));
        }
        return ResponseEntity.ok().body(true);
    }
}
